<?php
class C_usergroups extends CI_Controller {
	function __construct(){
		parent::__construct();
		checkLogin();
		$this->load->model('m_usergroups');
	}
	function index(){
		$task = secure_post('task');
		switch($task){
			case 'LIST' :
				$this->_list();
				break;
			case 'INSERT' :
				$this->_insert();
				break;
			case 'UPDATE' :
				$this->_update();
				break;
			case 'DELETE' :
				$this->_delete();
				break;
			default :
				$data["s_menus"] = $this->m_usergroups->s_menus();
				$this->load->view('v_usergroups',$data);
		}
	}
	
	function _list(){
		$data['page'] = numeric_post("page");
		$data['rows'] = numeric_post("rows");
		$data['group_name'] = nosql_post("group_name");
		$data['group_desc'] = nosql_post("group_desc");
		echo $this->m_usergroups->_list($data);
	}
	
	function _insert(){
		$menu = ($this->input->post('menu'));
		$data = array(
			'group_name' => $this->input->post('group_name'), 
			'group_desc' => $this->input->post('group_desc'), 
			  
			'usergroups_sys_active'=> '1',
			'usergroups_sys_owner'	=>$_SESSION[SESSION_USERID]);
		$this->m_usergroups->_insert($data,$menu );
		echo 1;
	}
	
	function _update(){
		$menu = ($this->input->post('menu'));
		$group_id = $this->input->post('group_id');
		$data = array(
			'group_name' => $this->input->post('group_name'), 
			'group_desc' => $this->input->post('group_desc'), 
			
			'usergroups_sys_owner'	=> $_SESSION[SESSION_USERID],
			'usergroups_sys_update'=> date("Y-m-d h:i:s"));
		$this->m_usergroups->_update($data,$group_id,$menu );
		echo 1;
 	}
	
	function _delete(){
		$group_id= $this->input->post('group_id');
		$data = array(
			'usergroups_sys_active' => '0',
			'usergroups_sys_owner'	=> $_SESSION[SESSION_USERID],
			'usergroups_sys_delete'=> date("Y-m-d h:i:s")
		);
		$this->m_usergroups->_delete($data,$group_id);
		echo 1;
	}
}